const currency = function (value) {
  console.log(value)
  return value + 1
};
const getFileType =function (fileName) {
  if(fileName){
    let arr = fileName.split('.');
    return arr[1]
  }
  return ''
}
const timeFilter = function (time, fmt = "yyyy-MM-dd HH:mm:ss") {
  let date = new Date(time);
  let o = {
    "M+" : date.getMonth()+1, //月份
    "d+" : date.getDate(), //日
    "h+" : date.getHours()%12 == 0 ? 12 : date.getHours()%12, //小时
    "H+" : date.getHours(), //小时
    "m+" : date.getMinutes(), //分
    "s+" : date.getSeconds(), //秒
    "q+" : Math.floor((date.getMonth()+3)/3), //季度
    "S" : date.getMilliseconds() //毫秒
  };
  let week = {
    "0" : "/u65e5",
    "1" : "/u4e00",
    "2" : "/u4e8c",
    "3" : "/u4e09",
    "4" : "/u56db",
    "5" : "/u4e94",
    "6" : "/u516d"
  };
  if(/(y+)/.test(fmt)){
    fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  }
  if(/(E+)/.test(fmt)){
    fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[date.getDay()+""]);
  }
  for(let k in o){
    if(new RegExp("("+ k +")").test(fmt)){
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    }
  }
  return fmt;
};
function addZero (number) {
  if(number<10){
    return '0'+number.toString();
  }else {
    return number.toString();
  }
}
const userTimeFilter = function (time,format= '-') {
   // 时间显示规则
   //1 与当前时间差距 大于一个礼拜（7）显示年月日
  //2 大于2天-7天之内 显示星期几
  //3 大于一天 显示为昨天
  // 小于一天 即当天如果为上午 小于13h为上午 大于13显示为下午
  let currentDay =  new Date(time);
  let day  = new Date();
  let currentObj = {
    "Y" : currentDay.getFullYear(),
    "M": currentDay.getMonth()+1,
    "d": currentDay.getDate(), //日
    "h": currentDay.getHours()%12 === 0 ? 12 : currentDay.getHours()%12, //小时
    "H" : currentDay.getHours(), //小时
    "m": currentDay.getMinutes(), //分
    "s": currentDay.getSeconds(), //秒
    "q": Math.floor((currentDay.getMonth()+3)/3), //季度
    "S": currentDay.getMilliseconds() //毫秒
  };
  let dayObj = {
    "d" : day.getDate(), //日
  };
  let formateDate ='';
  if(currentObj.d -dayObj.d === 0){
    formateDate= addZero(currentObj.H) +':'+ addZero(currentObj.m);
    return formateDate;
  }else{
    formateDate = currentObj.Y+format+currentObj.M+format+currentObj.d
    return formateDate;
  }

};
export default {
  currency,
  timeFilter,
  userTimeFilter,
  getFileType
}
